$('#title').html('支付');
$('#paybody').attr('data-bundcardid',sessionStorage.bankCardId);
$('#paybody').children('img').attr('src',sessionStorage.bankLogo);
$('#paybody').children('.flex-1').html(sessionStorage.bankName+'&nbsp;信用卡&nbsp;<span style="color: #aaa;">尾号'+sessionStorage.cardNo.split(' ')[3]+'</span>')
$('#capitalAmount').text(sessionStorage.capitalAmount);
$('#poundageTotalAmt').text('保证金含手续费'+sessionStorage.poundageTotalAmt+'元');
//渲染支付列表
Cardlist.getPayCardList({
			method: 'plan.pay.cards',
			version: '1.0.2',
			userId: localStorage.rpUserId
		}, function(res){
		//显示支付列表
		$('#paybody').click(function(){
				$('#paymodel').show();
				$('#bankCardbox').animate({left:'0'});
				$('#verificationbox').css('display','none');
				var myScroll = new IScroll('#bankCardcont',{mouseWheel: true,click: true,tap: true});				
				// 银行卡列表点击事件
				$('.item').click(function(){
				$('#paybody').children('img').attr('src',$(this).children('img').attr('src')); //银行logo
				$('#paybody').children('.flex-1').html($(this).children('p').html()); //银行提示
				localStorage.bundcardid =  $(this).attr('data-bundcardid'); //缓存支付银行卡Id
				localStorage.cardtype = $(this).attr('data-cardtype'); //解决切换卡后cardtype不对
				$('#paybody').attr('data-phone', $(this).attr('data-phone')); //预留手机号 
				$('#paybody').attr('data-quick',$(this).attr('data-quick')); //支付卡类型
//				$('#paybody').attr('data-cardtype',$(this).attr('data-cardtype')); //支付卡类型
				if($(this).data('quick') == 0){ //判断是否开通快捷，0未开通，显示验证码
					$('#verificationbox').css('display','flex');
				}
				$(this).children('.icon-gou').show();
				$(this).siblings().children('.icon-gou').hide();
				$('#bankCardbox').animate({left:'1000px'});
				setTimeout(function() {$('#paymodel').hide();},200);
				});
		});		
		//隐藏支付列表
		$('.bankCardhead').click(function(){
			$('#bankCardbox').animate({left:'-1000px'});
			setTimeout(function() {$('#paymodel').hide();},200);
		});
});

//获取支付鉴权验证码
$('.getems').click(function(){
			var phone = $('#paybody').data('phone').toString();
				phone = phone.substr(0, 3)+'****'+phone.substr(7, 11);
		  	VerifyCode.getVerifyCode({
		    	method: 'plan.sendsms',
		    	version: '1.0.2',
		    	userId: localStorage.rpUserId, 
		    	bundCardId: localStorage.bundcardid, //取用缓存支付银行卡id
		    	cardType: localStorage.cardtype //卡类型，0=储蓄卡，1=信用卡
		    },function(res){
		    	layer.open({content:'验证码已发送至'+phone,skin: 'msg',time: 2});
		    });
});

//确认支付
$('.confirm').click(function(){
	var tradeAmt = Number($('#capitalAmount').text())*100;
	verifyCode = $.trim($('#verification').val());
	if($(paybody).data('quick') == 0){
		if(verifyCode != ''){
		Pay.planPayment({
			method: 'plan.payment',
			version: '1.0.2',
			userId: localStorage.rpUserId,
			reBundCardId: sessionStorage.bankCardId, //还款卡id
			payBundCardId: localStorage.bundcardid, //支付卡id
			cardType: localStorage.cardtype, //支付卡类型
			tradeAmt: tradeAmt, //保证金， 单位分
			batchNo: sessionStorage.batchNo, //批次号
			verifyCode: verifyCode //验证码
		},function(res){
			//支付成功后跳转到支付成功页面
			location.hash = 'paysuccess';
		})
		}else{
			layer.open({content:'请填写验证码',skin: 'msg',time: 2});
		}
	}else{
		Pay.planPayment({
			method: 'plan.payment',
			version: '1.0.2',
			userId: localStorage.rpUserId,
			reBundCardId: sessionStorage.bankCardId, //还款卡id
			payBundCardId: localStorage.bundcardid, //支付卡id
			cardType: localStorage.cardtype, //支付卡类型
			tradeAmt: tradeAmt, //保证金， 单位分
			batchNo: sessionStorage.batchNo, //批次号
			verifyCode: ''//验证码
		},function(res){
			//支付成功后跳转到支付成功页面
			location.hash = 'paysuccess';
		})
	}
});



